package com.ellricky.baselib.ui.clue

import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.clue.ClueAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.MyClueData
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback
import com.ellricky.baselib.util.jump

class MyClueChildFragment : BaseRefreshFragment<Void, BasePresenter<Void>, MyClueData>() {

    private var type = ""
    private var ctId = ""
    private var clueStateLevel = ""
    private var keyword = ""

    companion object {
        fun newInstance(index: String, ctId: String = ""): MyClueChildFragment {
            val fragment = MyClueChildFragment()
            val bundle = Bundle()
            bundle.putString("index", index)
            bundle.putString("ctId", ctId)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initUIView(view: View?) {
        type = arguments?.getString("index") ?: ""
        ctId = arguments?.getString("ctId") ?: ""
        super.initUIView(view)
        hideToolBar()
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<MyClueData>(mContext) {
            override fun onSuccess(data: MutableList<MyClueData>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<MyClueData> = ClueAdapter()

    override fun getUrlPath(): String {
        return ""
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap["action"] = "saleClueList"
        paramMap["clue_state"] = type
        paramMap["school_id"] = LocalCacheUtil.getSchoolId()
        paramMap["search_key"] = keyword
        paramMap["eid"] = if (ctId.isNotEmpty()) ctId else LocalCacheUtil.getUid()
        paramMap["clue_state_level"] = clueStateLevel
    }

    fun refresh(intent: String) {
        this.clueStateLevel = intent
        rvView.loadContent(true)
    }

    fun search(keyword:String){
        this.keyword = keyword
        rvView.loadContent(true)
    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, i: Int, l: Long) {
        super.onItemClick(adapterView, view, i, l)
        val id = adapter[i].clue_id
        val returnId = adapter[i].return_id.toString()
        jump<CluePoolDetailActivity> {
            putExtra(BaseConstant.KEY_ID, id)
            putExtra(BaseConstant.KEY_RETURN_ID, returnId)
        }
    }
}
